package com.zidian.study.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.zidian.student.trucks.R;
import com.zidian.study.fragment.AllQuestionFragment;
import com.zidian.study.fragment.MyQuestionFragment;
import com.zidian.study.globa.AppActivity;
import com.zidian.study.globa.BaseFragment;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by GongCheng on 2016/12/19.
 */

public class QuestionActivity extends AppActivity {
    @Bind(R.id.my_questions_tv)
    TextView myQuestionsTv;
    @Bind(R.id.all_questions_tv)
    TextView allQuestionsTv;

    private boolean isFirst = true;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_question;
    }

    @Override
    protected int getFragmentContentId() {
        return R.id.fragment_container;
    }

    @Override
    protected BaseFragment getFirstFragment() {
        return AllQuestionFragment.newInstance();
    }

    @OnClick(R.id.question_add)
    public void addQuestion() {
        startActivity(new Intent(this , InteractionQuestionAddActivity.class));
    }

    @OnClick(R.id.toolbar_back)
    public void back() {
        onBackPressed();
    }

    @OnClick({R.id.all_questions_tv,R.id.my_questions_tv})
    public void selectQuestions(View view) {
        switch (view.getId()) {
            case R.id.all_questions_tv:
                if (!isFirst) {
                    isFirst = true;
                    allQuestionsTv.setBackgroundResource(R.drawable.bg_task_work_tab_select);
                    allQuestionsTv.setTextColor(getResources().getColor(R.color.colorPrimary));
                    myQuestionsTv.setBackgroundResource(R.drawable.bg_task_action_tab);
                    myQuestionsTv.setTextColor(getResources().getColor(R.color.white));
                    addFragment(AllQuestionFragment.newInstance());
                }
                break;
            case R.id.my_questions_tv:
                if (isFirst) {
                    isFirst = false;
                    allQuestionsTv.setBackgroundResource(R.drawable.bg_task_work_tab);
                    allQuestionsTv.setTextColor(getResources().getColor(R.color.white));
                    myQuestionsTv.setBackgroundResource(R.drawable.bg_task_action_tab_select);
                    myQuestionsTv.setTextColor(getResources().getColor(R.color.colorPrimary));
                    addFragment(MyQuestionFragment.newInstance());
                }
                break;
        }
    }


}
